/// @FUNCTION
/// @NAME HashDump
/// @DESC Dumps the content of an hash array to the Log file
/// @ACCESS Server
/// @MP False
/// @PARAM Array The hash table
/// @RETURN Nothing
/// @REQUIRE Nothing
/// @REMARK
/// @EXAMPLE [_instances] call CFUNC(HashDump);

//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "arrays\fn_hashDump.sqf"
#include <tmf_constants.h>
#include <tmf_macros.h>
#ifndef __DUMP_INDENT__
#define __DUMP_INDENT__	"    "
#endif

private ["_hash_array","_hash_key","_hash_indexer","_index","_hash_values","_value","_indent","_indentval","_i"];
TMFPROFILERSTART;

_result = false;
if (typeName _this == typename []) then {
	if (count _this >= 1) then {
		_hash_array = _this select 0;
		if (typeName _hash_array == typename []) then {
			if (count _hash_array >= 2) then {
				_hash_indexer = _hash_array select 0;
				_hash_values = _hash_array select (count _hash_array - 1);
				_indent = __DUMP_INDENT__;
				diag_log "";
				diag_log Format["%1DUMP HASH ARRAY: %2",_indent, count _hash_indexer];
				diag_log Format["%1-----------------------",_indent];
				_indent = _indent + __DUMP_INDENT__;
				for "_i" from 0 to (count _hash_indexer - 1) do {
					_indentval = _indent + __DUMP_INDENT__;
					_hash_key = _hash_indexer select _i;
					diag_log Format["%1 [%2]",_indent, _hash_key];
					_index = _hash_indexer find _hash_key;
					if ((_index > 0) && (_index < count _hash_values)) then {
						_value = _hash_values select _index;
						if (typeName _value == typename []) then {
							[_value,_indentval] call CFUNC(ArrayDump);
						} else {
							diag_log Format["%1 %2",_indentval,_value];
						};
					} else {
						diag_log Format["%1 %2",_indentval,"(Out of bounds)"];
					};
				};
			};				
			if ((isNil "_result") && !(IsNil "_default")) then { _result = _default };
		};
	};
};
TMFPROFILERSTOP;